[Java] Charset encoding handling improvements. #887
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains several improvements to how charset encoding is handled by the
JavaGenerator:lAtIN1will be resolved toStandardCharsets.ISO_8859_1. This is similar to howCharset.forName(String)works.StandardCharsetswhen generating staticCharacterEncodingmethods, e.g.java.nio.charset.StandardCharsets.ISO_8859_1.name()will be used instead of a string"latin1"(whencharacterEncoding=latin1).characterEncoding=cp912is specified the resolved name will beISO-8859-2and will be used everywhere the original name would have been used. If the charset does not exist at the code generation time then the raw value is used.putStringWithoutLengthAsciifor methods taking aCharSequence.Charsetinstance when converting to/from String. This eliminates most of thetry/catchblocks in the generated code.byte[]when input string is null or empty.